#include "listitembox.h"
#include "ui_listitembox.h"

ListItemBox::ListItemBox(QWidget *parent)
    : QWidget(parent)
    ,ui(new Ui::ListItemBox)
    , _isLike(false)
{
    ui->setupUi(this);

    connect(ui->likeBtn, &QPushButton::clicked,this,&ListItemBox::onLikeBtnCliked);
}

ListItemBox::~ListItemBox()
{
    delete ui;
}


void ListItemBox::setMusicName(const QString &MusicName)
{
    ui->musicNameLabel->setText(MusicName);
}

void ListItemBox::setSingerName(const QString &SingerName)
{
    ui->musicSingerLabel->setText(SingerName);
}

void ListItemBox::setAblumName(const QString &AblumName)
{
    ui->albumNameLabel->setText(AblumName);
}

//设置图标
void ListItemBox::setIcon(bool isLike)
{
    _isLike = isLike;
    if(isLike){
        ui->likeBtn->setIcon(QIcon(":/images/love2.png"));

    }
    else{
        ui->likeBtn->setIcon(QIcon(":/images/love.png"));
    }
}

void ListItemBox::leaveEvent(QEvent *event)
{
    (void)event;
    setStyleSheet("");
}


void ListItemBox::onLikeBtnCliked()
{
    //设置为相反的状态
    _isLike = !_isLike;

    //设置图标
    //发送信号
    emit setIsLike(_isLike);
}

void ListItemBox::enterEvent(QEnterEvent *event)
{
    (void)event;
    setStyleSheet("background-color:#EFEFEF");

}

